<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/new.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons">
          <a onclick="location = '<?php echo $insert; ?>'" class="button"><span><?php echo $button_insert; ?></span></a>
          <a onclick="$('form').submit();" class="button"><span><?php echo $button_delete; ?></span></a>
          <a onclick="public_id();" class="button"><span>Public</span></a>
          <a onclick="unpublic_id();" class="button"><span>Unpublic</span></a>

      </div>

    </div>
    <div class="content">
      <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
              <td class="left"><?php if ($sort == 'id.title') { ?>
                <a href="<?php echo $sort_title; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_title; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_title; ?>"><?php echo $column_title; ?></a>
                <?php } ?></td>
              <td class="right"><?php if ($sort == 'i.sort_order') { ?>
                <a href="<?php echo $sort_sort_order; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_sort_order; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_sort_order; ?>"><?php echo $column_sort_order; ?></a>
                <?php } ?></td>
              <td class="right">Status</td>
              <td class="right">Image</td>
              <td class="right"><?php echo $column_action; ?></td>
            </tr>
          </thead>
          <tbody>
            <?php if ($news) {

            ?>
            <?php foreach ($news as $new) {
            ?>
            <tr>
              <td style="text-align: center;"><?php if ($new['selected']) { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $new['news_id']; ?>" checked="checked" />
                <?php } else { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $new['news_id']; ?>" />
                <?php } ?>

            </td>
              <td class="left"><?php echo $new['title']; ?></td>

              <td class="right"><?php echo $new['sort_order']; ?></td>
            <td class="right"><?php if ($new['status'] == 1) { echo "Enabled"; ?>
                <?php } else {  echo "Disabled"; ?>

                <?php } ?>



              <td class="center"><img src="<?php echo $new['image']; ?>" alt="<?php echo $new['title']; ?>" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
              <td class="right"><?php foreach ($new['action'] as $action) { ?>

                  [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="4"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<?php echo $footer; ?>
<script type="text/javascript">
    function public_id(){
        var ids = [];
        $('input[name="selected[]"]:checked').each(function(i){
            ids[i] = $(this).val();
        });
        if(ids.length>0){
            $.post("index.php?route=catalog/news_content/public_id&token=<?php echo $token; ?>", $("#form").serialize(),
                    function(resp) {
                        if(resp == "success"){
                            location = 'index.php?route=catalog/news_content&token=<?php echo $token; ?>';
                        }else{
                            alert("Error. Not Public !");
                        }
                    });
        }else{
            alert("Bạn chưa chọn mục nào !");
        }
    }

    function unpublic_id(){
        var ids = [];
        $('input[name="selected[]"]:checked').each(function(i){
            ids[i] = $(this).val();
        });
        if(ids.length>0){
            $.post("index.php?route=catalog/news_content/unpublic_id&token=<?php echo $token; ?>", $("#form").serialize(),
                    function(resp) {
                        if(resp == "success"){
                            location = 'index.php?route=catalog/news_content&token=<?php echo $token; ?>';
                        }else{
                            alert("Error. Not Unpublic !");
                        }
                    });
        }else{
            alert("Bạn chưa chọn mục nào !");
        }
    }
</script>